package com.tiger.web.controller.bill;

import com.tiger.common.annotation.Log;
import com.tiger.common.core.controller.BaseController;
import com.tiger.common.core.domain.AjaxResult;
import com.tiger.common.core.domain.model.LoginUser;
import com.tiger.common.core.page.TableDataInfo;
import com.tiger.common.enums.BusinessType;
import com.tiger.common.utils.ServletUtils;
import com.tiger.common.utils.spring.SpringUtils;
import com.tiger.framework.web.service.TokenService;
import com.tiger.project.domain.ContractSponsor;
import com.tiger.project.domain.req.DepositChange;
import com.tiger.project.service.IContractSponsorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Author bai
 * Date on 2022/10/10  16:08
 * Description:押金管理
 */
@Api(tags = "押金管理")
@RestController
@RequestMapping("/system/deposit")
public class AssetReceiptDepositController extends BaseController {
    @Autowired
    private IContractSponsorService contractSponsorService;


    /**
     * 查询【押金管理】列表
     */
    @ApiOperation(value = "查询【押金管理】列表")
    //@PreAuthorize("@ss.hasPermi('system:sponsor:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractSponsor contractSponsor) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        contractSponsor.setCompanyId(loginUser.getUser().getDeptId());
        startPage();
        contractSponsor.setStatus(3L);
        List<ContractSponsor> list = contractSponsorService.selectContractSponsorList(contractSponsor);
        return getDataTable(list);
    }


    /**
     * 获取【押金管理】详细信息
     */
    @ApiOperation(value = "获取【押金管理】列详细信息")
    //@PreAuthorize("@ss.hasPermi('system:sponsor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(contractSponsorService.selectContractSponsorByDepositId(id));
    }

    /**
     * 变更【押金管理】
     */
    @ApiOperation(value = "变更【押金管理】")
    //@PreAuthorize("@ss.hasPermi('system:sponsor:edit')")
    @Log(title = "【押金管理】", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ContractSponsor contractSponsor) {
        return toAjax(contractSponsorService.updateReceiptDeposit(contractSponsor));
    }

    @ApiOperation(value = "押金管理变更审核回调")
    @GetMapping("/callBack")
    public AjaxResult callBack(Long id, String oaFile, BigDecimal cashPledge,String depositRemark,
                               String depositDecisionId,Long depositStatus) {
        return toAjax(contractSponsorService.callBackDeposit(id, oaFile, cashPledge, depositRemark, depositDecisionId, depositStatus));
    }

    @ApiOperation(value = "押金管理收款审核回调")
    @GetMapping("/payee/callBack")
    public AjaxResult payeeCallBack(Long id, String oaFile, BigDecimal depositPayeeMoney, String depositPayeeNum,
                                    String depositPayeeFile, Long depositPayeeStatus, Date depositPayeeTime) {
        return toAjax(contractSponsorService.callBackDepositPayee(id, oaFile, depositPayeeMoney, depositPayeeNum, depositPayeeFile,
                                                                    depositPayeeStatus,depositPayeeTime));
    }

    @ApiOperation(value = "押金管理退款审核回调")
    @GetMapping("/refund/callBack")
    public AjaxResult refundCallBack(Long id, String oaFile,BigDecimal depositRefundMoney,String depositRefundNum,
                                     String depositRefundFile,Long depositRefundStatus,Date depositRefundTime) {
        return toAjax(contractSponsorService.callBackDepositRefund(id, oaFile, depositRefundMoney, depositRefundNum, depositRefundFile,
                depositRefundStatus,depositRefundTime));
    }

}
